package com.llsydn.demo.animation1;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.llsydn.hello.R;

/**
 * @author lilinshen
 * @title 动画demo，欢迎界面动画。
 * @description 请填写相关描述
 * @date 2018/10/10 10:23
 */
public class AnimationFirstActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText et_username;
    private Button btn_login;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animation_first);

        et_username = findViewById(R.id.et_username);
        btn_login = findViewById(R.id.btn_login);

        btn_login.setOnClickListener(this);
    }

    /**
     * 点击登录
     *
     * @param v
     */
    @Override
    public void onClick(View v) {
        //得到输入框的文本
        String name = et_username.getText().toString();
        //判断是否是空串, 如果为空串, 显示抖动动画
        if ("".equals(name.trim())) {
            Animation animation = AnimationUtils.loadAnimation(AnimationFirstActivity.this, R.anim.shake);
            et_username.startAnimation(animation);
        } else {
            //否则, 提示登陆
            Toast.makeText(AnimationFirstActivity.this, "去登陆", Toast.LENGTH_SHORT).show();
        }
    }
}
